
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Specialized;
using System.Xml;
using System.IO;
using System.Collections.Generic;
using IPickImporterUI.UtilObjects;


namespace IPickImporterUI
{
	public  class Catalog
	{
		private long _CatalogId;
		private string _ProviderCatalogId;
		private string _Title;
		private string _PosterSmall;
		private string _PosterMedium;
		private string _PosterLarge;
		private int _ReleaseYear;
		private string _MPAA_Rating;
		private string _Description;
		private string _ViewerRating;
		//private bool _isNew;

		#region Constructors
		
        public Catalog(DataTable dt)
        {
            //build the catalog from the datatable only the columns we want
            
        }
		public Catalog()
		{
			
		}
		
		public Catalog(long CatalogId) : this()
		{
			_CatalogId = CatalogId;
		}

        public Catalog(long CatalogId, string ProviderCatalogId, string Title, string PosterSmall, string PosterMedium, string PosterLarge, int ReleaseYear, string MPAA_Rating, string Description, string ViewerRating)
            : this()
		{
			_CatalogId = CatalogId;
			_ProviderCatalogId = ProviderCatalogId;
			_Title = Title;
			_PosterSmall = PosterSmall;
			_PosterMedium = PosterMedium;
			_PosterLarge = PosterLarge;
			_ReleaseYear = ReleaseYear;
			_MPAA_Rating = MPAA_Rating;
			_Description = Description;
			_ViewerRating = ViewerRating;
		}

		#endregion
		
		#region Properties
		
		public long CatalogId
		{
			get	{ return _CatalogId; }
			set	{ _CatalogId = value; }
		}
		
		public string ProviderCatalogId
		{
			get	{ return _ProviderCatalogId; }
			set	{ _ProviderCatalogId = value; }
		}
		
		public string Title
		{
			get	{ return _Title; }
			set	{ _Title = value; }
		}
		
		public string PosterSmall
		{
			get	{ return _PosterSmall; }
			set	{ _PosterSmall = value; }
		}
		
		public string PosterMedium
		{
			get	{ return _PosterMedium; }
			set	{ _PosterMedium = value; }
		}
		
		public string PosterLarge
		{
			get	{ return _PosterLarge; }
			set	{ _PosterLarge = value; }
		}
		
		public int ReleaseYear
		{
			get	{ return _ReleaseYear; }
			set	{ _ReleaseYear = value; }
		}
		
		public string MPAA_Rating
		{
			get	{ return _MPAA_Rating; }
			set	{ _MPAA_Rating = value; }
		}
		
		public string Description
		{
			get	{ return _Description; }
			set	{ _Description = value; }
		}
		
		public string ViewerRating
		{
			get	{ return _ViewerRating; }
			set	{ _ViewerRating = value; }
		}
		
        //public bool IsNew
        //{
        //    get 
        //    { 
        //        _isNew = (_CatalogId == 0);
        //        return _isNew; 
        //    }
        //    set { _isNew = value; }
        //}
		
		#endregion		


		/// <summary>
		/// Utility function that returns a DBNull.Value if requested. The comparison is done inline
		/// in the Insert() and Update() functions.
		/// </summary>
		private object SetNullValue(bool isNullValue, object value)
		{
			if (isNullValue)
				return DBNull.Value;
			else
				return value;
		}

       
        /// <summary>
        /// Take the Netflix Catalog and makes a IPick Catalog Object out of it
        /// </summary>
        /// <param name="oCatalog"></param>
        /// <returns></returns>
        public static List<Catalog> GenerateListFromNetFlix(NetFlixCatalog.NetflixCatalog oCatalog)
        {
            List<Catalog> catalogList = new List<Catalog>();
            Catalog singleCataLog = null;


            foreach (NetFlixCatalog.Title oSingleTitle in oCatalog.Titles)
            {
                //TODO: let's make the mapping blindly and generic
                singleCataLog = new Catalog(
                                                0,
                                                oSingleTitle.Id,
                                                oSingleTitle.Name,
                                                oSingleTitle.BoxArt.SmallUrl,
                                                oSingleTitle.BoxArt.MediumUrl,
                                                oSingleTitle.BoxArt.LargeUrl,
                                                Convert.ToInt16(oSingleTitle.ReleaseYear),
                                                oSingleTitle.Rating,
                                                oSingleTitle.Synopsis,
                                                oSingleTitle.AverageRating.ToString()
                                            );

                catalogList.Add(singleCataLog);

            }
            return catalogList;
        }
	}
}
